package com.ruoyi.back.controller;

import java.util.List;

import com.ruoyi.back.domain.IndustryConsulting;
import com.ruoyi.back.service.IIndustryConsultingService;
import com.ruoyi.common.utils.uuid.SnowflakeIdUtils;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 行业资讯Controller
 * 
 * @author luguanqing
 * @date 2021-04-06
 */
@Api(value="行业资讯信息",description = "行业资讯信息接口")
@RestController
@RequestMapping("/back/consulting")
public class IndustryConsultingController extends BaseController
{
    @Autowired
    private IIndustryConsultingService industryConsultingService;

    /**
     * 查询行业资讯列表
     */
    //@PreAuthorize("@ss.hasPermi('system:consulting:list')")
    @ApiOperation(value="查询行业资讯列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "页数", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "每页记录数", required = true, dataType = "String"),
    })
    @GetMapping("/list")
    public TableDataInfo list(IndustryConsulting industryConsulting)
    {
        startPage();
        List<IndustryConsulting> list = industryConsultingService.selectIndustryConsultingList(industryConsulting);
        return getDataTable(list);
    }

    /**
     * 导出行业资讯列表
     */
    //@PreAuthorize("@ss.hasPermi('system:consulting:export')")
    @Log(title = "行业资讯", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(IndustryConsulting industryConsulting)
    {
        List<IndustryConsulting> list = industryConsultingService.selectIndustryConsultingList(industryConsulting);
        ExcelUtil<IndustryConsulting> util = new ExcelUtil<IndustryConsulting>(IndustryConsulting.class);
        return util.exportExcel(list, "consulting");
    }

    /**
     * 获取行业资讯详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:consulting:query')")
    @ApiOperation(value="获取行业资讯详情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam(name="id",value="资讯id",required=true)@PathVariable("id") String id)
    {
        return AjaxResult.success(industryConsultingService.selectIndustryConsultingById(id));
    }

    /**
     * 新增行业资讯
     */
    //@PreAuthorize("@ss.hasPermi('system:consulting:add')")
    @ApiOperation(value="新增行业资讯")
    @Log(title = "行业资讯", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam(name="行业资讯对象",value="传入json格式",required=true)@RequestBody IndustryConsulting industryConsulting)
    {
        industryConsulting.setId(String.valueOf(new SnowflakeIdUtils(0, 0).nextId()));
        return toAjax(industryConsultingService.insertIndustryConsulting(industryConsulting));
    }

    /**
     * 修改行业资讯
     */
    //@PreAuthorize("@ss.hasPermi('system:consulting:edit')")
    @ApiOperation(value="修改行业资讯")
    @Log(title = "行业资讯", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam(name="行业资讯对象",value="传入json格式",required=true)@RequestBody IndustryConsulting industryConsulting)
    {
        return toAjax(industryConsultingService.updateIndustryConsulting(industryConsulting));
    }

    /**
     * 资讯浏览记录+1
     */
    //@PreAuthorize("@ss.hasPermi('system:information:edit')")
    @ApiOperation(value="资讯浏览记录+1")
    @Log(title = "资讯信息", businessType = BusinessType.UPDATE)
    @GetMapping(value = "/visitUp/{id}")
    public AjaxResult visitUp(@ApiParam(name="id",value="资讯id",required=true)@PathVariable("id") String id)
    {
        return toAjax(industryConsultingService.updateVisit(id));
    }

    /**
     * 删除行业资讯
     */
    //@PreAuthorize("@ss.hasPermi('system:consulting:remove')")
    @ApiOperation(value="删除行业资讯")
    @Log(title = "行业资讯", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam(name="id",value="行业资讯id",required=true)@PathVariable String[] ids)
    {
        return toAjax(industryConsultingService.deleteIndustryConsultingByIds(ids));
    }
}
